﻿/*
 * 创建人:lf
 * 创建时间:2021/5/20 10:29:15
 * 描述:
 * */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Furion.DependencyInjection;
using Furion.JsonSerialization;
using MapsterMapper;
using Microsoft.Extensions.Logging;
using Purchasing.Application.Company;
using Purchasing.Core.Dtos;

namespace Purchasing.Web.Core.Company
{
    public class CompanyCoreService:ICompanyCore
    {
        private readonly ILogger<CompanyCoreService> _logger;
        private readonly ICompany _company;
        private readonly IJsonSerializerProvider _jsonSerializer;
        private readonly IMapper _mapper;

        public CompanyCoreService(ILogger<CompanyCoreService> logger,ICompany  company , IJsonSerializerProvider  jsonSerializer,IMapper mapper)
        {
            this._logger = logger;
            this._company = company;
            this._jsonSerializer = jsonSerializer;
            this._mapper = mapper;
        }

       

        public async Task<string> GetAllAsync(string keyWord)
        {
            var list= await  _company.GetAll(keyWord);

            var dots = _mapper.Map<List<CompanyDto>>(list);
            _logger.LogInformation("获取了公司数据,并被格式化为字符串,最终返回给controller");
            return _jsonSerializer.Serialize(dots);
        }

    }
}
